package com.numberone.master.modules.sys.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.numberone.master.common.persistence.Page;
import com.numberone.master.common.service.CrudService;
import com.numberone.master.modules.sys.entity.Opinion;
import com.numberone.master.modules.sys.entity.User;
import com.numberone.master.modules.sys.utils.UserUtils;
import com.numberone.master.modules.sys.dao.OpinionDao;

/**
 * 意见反馈Service
 * @author ck
 * @version 2018-03-07
 */
@Service
@Transactional(readOnly = true)
public class OpinionService extends CrudService<OpinionDao, Opinion> {

	public Opinion get(String id) {
		return super.get(id);
	}
	
	public List<Opinion> findList(Opinion opinion) {
		return super.findList(opinion);
	}
	
	public Page<Opinion> findPage(Page<Opinion> page, Opinion opinion) {
		Page<Opinion> pages = super.findPage(page, opinion);
		List<Opinion> list = pages.getList();
		for (int i = 0; i < list.size(); i++) {
			String createId = list.get(i).getCreateBy().getId();
			User user = UserUtils.get(createId);
			if(user != null){
				String name = user.getLoginName();
				list.get(i).setCreateByName(name);
			}
		}
		pages.setList(list);
		return pages;
	}
	
	@Transactional(readOnly = false)
	public void save(Opinion opinion) {
		super.save(opinion);
	}

	@Transactional(readOnly = false)
	public void update(Opinion opinion) {
		super.update(opinion);
	}
	
	@Transactional(readOnly = false)
	public void delete(Opinion opinion) {
		super.delete(opinion);
	}
	
}